﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Manage.SqlServerDAL;

public partial class SysManage_Org_Type_Edit : System.Web.UI.Page
{
    DeptPersManage MyDp = new DeptPersManage();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GrantBtn1_ServerClick(object sender, EventArgs e)
    {
        string sHid = HID.Value.ToString().Trim();
        string sOrgtype = OrgType.Text.ToString().Trim();
        string sHOrgType = HOrgType.Value.ToString().Trim();
        string sOrgName = OrgName.Text.ToString().Trim();
        string sHOrgName = HOrgName.Value.ToString().Trim();
        string sDorder = Dorder.Text.ToString().Trim();
        string sHorder = HOrder.Value.ToString().Trim();
        string sEffective = Effective.SelectedValue.ToString().Trim();
        string sEditType = hidEditType.Value.ToString().Trim();

        if (sOrgName == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('类别名称不能为空!');</script>");
            return;
        }

        if (sOrgtype != sHOrgType)
        {
            int iorgtype = MyDp .JudgeOrgtypeInfo (sOrgtype);
            if (iorgtype >= 1)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('类别编码重复!');</script>");
                return;
            }
        }

        if (sOrgName != sHOrgName)
        {
            int iorgname = MyDp .JudgeOrgNameInfo (sOrgName);
            if (iorgname >= 1)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('类别名称重复!');</script>");
                return;
            }
        }

        if (sDorder.Trim() != sHorder.Trim () )
        {
            int iback3 = MyDp .JudgeOrgTypeOrder (sDorder);
            if (iback3 > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('排序号已重复!');</script>");
                return;
            }
        }


        if (sEditType == "1") // 新建
        {
            if (sOrgtype == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('类别编码不能为空!');</script>");
                return;
            }

            int back = MyDp .SaveOrgTypeInfo (sOrgtype, sOrgName, sDorder, sEffective);
            if (back >0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新建成功!');;window.close();</script>");
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新建失败!');</script>");
                return;
            }
        }
        else
        {
            int back = MyDp .UpOrgTypeInfo (sOrgtype, sOrgName, sDorder, sEffective, sHid);
            if (back >0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');;window.close();</script>");
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                return;
            }
        }
    }
}
